﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization;
using System.Xml.Serialization;

namespace XAMLStylePad.Models
{
    /// <summary>
    /// Source of styles and templates. It can be an assembly or source files
    /// </summary>
    //[Serializable]
    public abstract class SourceBase : ISerializable
    {
        public SourceBase()
        {
        }

        public SourceBase(string fullPath)
        {
            FullPath = fullPath;
        }

        public SourceBase(SerializationInfo info, StreamingContext context) : this(info.GetString("FullPath"))
        {
        }

        public string Name
        {
            get;
            set;
        }

        /// <summary>
        /// set full path and evaluate Name and Path properties
        /// </summary>
        public string FullPath
        {
            get
            {
                return _FullPath;
            }
            set
            {
                Name = Path.GetFileName(value);
                Directory = Path.GetDirectoryName(value);
                _FullPath = value;
            }
        }
        string _FullPath;

        public string Directory
        {
            get;
            set;
        }

        public bool IsLoaded
        {
            get;
            protected set;
        }

        public abstract bool IsReadOnly
        {
            get;
        }

        //#region Styles
        //public List<Style> Styles
        //{
        //    get
        //    {
        //        return _Styles;
        //    }
        //}
        //List<Style> _Styles = new List<Style>(); 
        //#endregion

        //#region Templates
        //public List<FrameworkTemplate> Templates
        //{
        //    get
        //    {
        //        return _Templates;
        //    }
        //}
        //List<FrameworkTemplate> _Templates = new List<FrameworkTemplate>();
        //#endregion

        #region Resources
        public List<ResourceDictionaryModel> Resources
        {
            get
            {
                return _Resources;
            }
            protected set
            {
                _Resources = value;
            }
        }
        [NonSerialized][XmlIgnore] List<ResourceDictionaryModel> _Resources = new List<ResourceDictionaryModel>();
        #endregion

        public abstract void Load();

        public abstract void Save(string path);

        #region ISerializable Members

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("FullPath", FullPath);
        }

        #endregion
    }
}
